package com.springboot.demo.core.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

/****************************************************
 *
 * 通用工具类
 *
 *
 * @author Francis
 * @date 2019/8/13 13:50
 * @version 1.0
 **************************************************/
@Slf4j
public class SysUtils {

    /**
     * MD5 加密
     * @param orginStr 原始字符串
     * @return
     */
    public static String encodeByMd5(String orginStr){
        String encode = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            Base64.Encoder encoder = Base64.getEncoder();

            encode = encoder.encodeToString(md5.digest(orginStr.getBytes("utf-8")));
        } catch (NoSuchAlgorithmException e) {
            log.error("设置md5计算方法失败！");
        } catch (UnsupportedEncodingException e) {
            log.error("md5加密失败！");
        }

        return encode;
    }

}
